#include "Judge_banner.h"

std::vector<point> Judge_banner::second_findlive;
std::vector<point> Judge_banner::second_findskip;


Judge_banner::Judge_banner() {}
//当前玩家编号crtP，棋盘状态board，以及要下棋的位置坐标I、J
int Judge_banner::IsDisallowed(int crtP,int board[N][N],int I,int J) {
    //返回是否触犯禁手规则
    //表示判断结果，初始值为0
    int judge_result = 0;
    //家在棋盘上活三的个数，大于1时会触犯禁手规则，将judge_result设置为1
    if (CountLiveThree(crtP, board,I,J) +CountSkipThree(crtP, board,I,J)> 1) {
        //std::cout << "33jinshou" << std::endl;
        judge_result = 1;

        for(int k=0;k<second_findlive.size();k++){
            if(SecondFour_Live(crtP,board,second_findlive[k])){
                judge_result = 0;
            }
        }
        for(int k=0;k<second_findskip.size();k++){
            if(SecondFour_Skip(crtP,board,second_findskip[k])){
                judge_result = 0;
            }
        }
        for(int k=0;k<second_findskip.size();k++){
            if(SecondFour_Long(crtP,board,second_findskip[k])){
                judge_result = 0;
            }
        }
    }
    //用于计算当前玩家在棋盘上活四的个数，大于1时会触犯禁手规则，将judge_result设置为2
    if (CountFour(crtP, board,I,J) > 1) {
        //std::cout << "44jinshou" << std::endl;
        judge_result = 2;
    }
    //判断是否存在长连，即连续五个或以上的同色棋子，如果存在长连，将judge_result设置为3
    //在判断了长连后，如果满足判断五连的条件，即JudgeFiveLink函数返回1将judge_result设置为4
    if (JudgeLongLink(crtP+1, board,I,J)) {//加一的原因是这个函数写的时候有点问题，懒得改了
        //std::cout << "chufachanglian" << std::endl;
        judge_result = 3;

    }

    if(judge_result!=0){
        if(JudgeFiveLink(crtP,board,I,J)==1){
            //cout<<"heiqishengli"<<endl;
            judge_result = 4;
        }
    }
    //表示判断结果，其中0表示未触犯禁手规则，1表示活三禁手，2表示活四禁手，3表示长连禁手，4表示黑棋胜利
    return judge_result;
}
//返回跳三的个数
int Judge_banner::CountSkipThree(int crtP, int board[N][N],int I,int J)
{
    int color, opponent_color;
    if (crtP == 0) {
        //玩家棋
        color = 1;
        opponent_color = 2;
    } else {
        //AI棋
        color = 2;
        opponent_color = 1;
    }
    second_findskip.clear();
    int skip_three_count = 0;
    //横向 - -- and -- -
    for (int j = max(0,J-4); j < min(11,J); j++)
    {
        int i=I;
        int drc=0;
        if (board[i][j] == 0 && board[i][j + 1] == color && board[i][j + 2] != opponent_color && board[i][j + 3] != opponent_color && board[i][j + 4] == color && board[i][j + 5] == 0 && (board[i][j + 1] + board[i][j + 2] + board[i][j + 3] + board[i][j + 4]) == 3 * color)
        {
            skip_three_count++;
            //std::cout << "发现横向跳三heng" << std::endl;
            point temp(i,j,drc);
            second_findskip.push_back(temp);
            break;
        }
    }
    //纵向 - -- and -- -
    for (int i = max(0,I-4); i < min(11,I); i++)
    {
        int j=J;
        int drc=1;
        if ( board[i][j] == 0 && board[i + 1][j] == color && board[i + 2][j] != opponent_color && board[i + 3][j] != opponent_color && board[i + 4][j] == color && board[i + 5][j] == 0 && (board[i + 1][j] + board[i + 2][j] + board[i + 3][j] + board[i + 4][j]) == 3 * color)
        {
            skip_three_count++;
            //std::cout << "发现纵向跳三shu" << std::endl;
            point temp(i,j,drc);
            second_findskip.push_back(temp);
            break;
        }
    }
    //"\"
    int k=min(I-4,J-4);
    if(k>=0) k=4;
    else k=k+4;
    for (int i = I-k,j = J-k; i < min(11,I)&&j< min(11,J); j++,i++) {
        int drc=2;
        if (board[i][j] == 0 && board[i + 1][j + 1] == color && board[i + 2][j + 2] != opponent_color && board[i + 3][j + 3] != opponent_color && board[i + 4][j + 4] == color && board[i + 5][j + 5] == 0 && (board[i + 1][j + 1] + board[i + 2][j + 2] + board[i + 3][j + 3] +board[i + 4][j + 4]) == 3 * color)
        {
            skip_three_count++;
            //std::cout << "发现纵向跳三youxie" << std::endl;
            point temp(i,j,drc);
            second_findskip.push_back(temp);
            break;
        }
    }
    //"/"
    k=min(I-4,14-J-4);
    if(k>=0) k=4;
    else k=k+4;
    for (int i = I-k,j = J+k; i < min(11,I)&&j> max(4,J); j--,i++)
    {

        int drc=3;
        if ( board[i][j] == 0 && board[i + 1][j - 1] == color && board[i + 2][j - 2] != opponent_color && board[i + 3][j - 3] != opponent_color && board[i + 4][j - 4] == color && board[i + 5][j - 5] == 0 &&(board[i + 1][j - 1] + board[i + 2][j - 2] + board[i + 3][j - 3] + board[i + 4][j - 4]) == 3 * color)
        {
            skip_three_count++;
            //std::cout << "发现纵向跳三zuoxie" << std::endl;
            point temp(i,j,drc);
            second_findskip.push_back(temp);
            break;
        }
    }
    return skip_three_count;
}


//返回连三的个数
int Judge_banner::CountLiveThree(int crtP, int board[N][N],int I,int J)
{

    int color, opponent_color;
    if (crtP == 0) {
        //玩家棋
        color = 1;
        opponent_color = 2;
    } else {
        //AI棋
        color = 2;
        opponent_color = 1;
    }
    second_findlive.clear();
    int live_three_count = 0;

    //横向 - -- and -- -
    for (int j = max(0,J-3); j < min(11,J); j++)
    {
        int i=I;
        int drc=0;
        if ( board[i][j] == 0 && board[i][j + 1] == color && board[i][j + 2] == color && board[i][j + 3] == color && board[i][j + 4] == 0  )
        {
            switch(j)
            {
            case 0:
                if( board[i][5] == 0 ) live_three_count++;
                break;
            case 10:
                if( board[i][9] == 0 ) live_three_count++;
                break;
            default:
                if((board[i][j-1] == 0||board[i][j+5] == 0)&&board[i][j-1] != color&&board[i][j+5] != color) live_three_count++;
                break;
            }
            //std::cout << "发现横向连三henghuo" << std::endl;

            point temp(i,j,drc);
            second_findlive.push_back(temp);
            break;
        }
    }
    //纵向 - -- and -- -
    for (int i = max(0,I-3); i < min(11,I); i++)
    {
        int j=J;
        int drc=1;
        if ( board[i][j] == 0 && board[i + 1][j] == color && board[i + 2][j] == color && board[i + 3][j] == color && board[i + 4][j] == 0 )
        {
            switch(i)
            {
            case 0:
                if( board[5][j] == 0 ) live_three_count++;
                break;
            case 10:
                if( board[9][j] == 0 ) live_three_count++;
                break;
            default:
                if((board[i-1][j] == 0||board[i+5][j] == 0)&&board[i-1][j] != color&&board[i+5][j] != color) live_three_count++;
                break;
            }
            //std::cout << "发现纵向连三zonghuo" << std::endl;
            point temp(i,j,drc);
            second_findlive.push_back(temp);
            break;
        }
    }
    //"\"
    int k=min(I-3,J-3);
    if(k>=0) k=3;
    else k=k+3;
    for (int i = I-k,j = J-k; i < min(10,I)&&j< min(10,J); j++,i++) {
        int drc=2;
        if ( board[i][j] == 0 && board[i + 1][j + 1] == color && board[i + 2][j + 2] == color && board[i + 3][j + 3] == color && board[i + 4][j + 4] == 0 )
        {
            if(i > 0 && i < 10 && j > 0 && j < 10)
            {
                if((board[i-1][j-1] == 0 || board[i+5][j+5] == 0)&&board[i-1][j-1] != color&&board[i+5][j+5] != color) live_three_count++;
            }
            else if (j == 0 ||i==0 ){
                if(board[i+5][j+5] == 0) live_three_count++;
            }
            else if(i==10||j==10){
                if(board[i-1][j-1] == 0) live_three_count++;
            }

            //std::cout << "发现左斜向连三   zuohuo" << std::endl;
            point temp(i,j,drc);
            second_findlive.push_back(temp);
            break;
        }
    }
    //"/"
    k=min(I-3,14-J-3);
    if(k>=0) k=3;
    else k=k+3;
    for (int i =I-k,j = J+k; i < min(10,I)&&j>= max(5,J+1); j--,i++)
    {

        int drc=3;
        if ( board[i][j] == 0 && board[i + 1][j - 1] == color && board[i + 2][j - 2] == color && board[i + 3][j - 3] == color && board[i + 4][j - 4] == 0  )
        {

            if( i != 0 && j != 14 && i != 10 && j != 4)
            {
                if((board[i-1][j+1] == 0 || board[i+5][j-5] == 0)&&board[i-1][j+1]!=color&&board[i+5][j-5] != color) live_three_count++;
            }
            else if(i==0||j==14){
                if( board[i+5][j-5] == 0) live_three_count++;
            }
            else if(i==10||j==4){
                if( board[i-1][j+1] == 0) live_three_count++;
            }
            //std::cout << "发现右斜向连三 youhuo" << std::endl;
            point temp(i,j,drc);
            second_findlive.push_back(temp);
            break;
        }
    }
    return live_three_count;
}
//计算冲四、活四的个数
int Judge_banner::CountFour(int crtP, int board[N][N],int I,int J)
{

    //棋盘转换
    I++;J++;
    int board1[17][17]={!crtP+1};
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            board1[i+1][j+1]=board[i][j];
        }
    }

    int color, opponent_color;
    if (crtP == 0) {
        //玩家棋
        color = 1;
        opponent_color = 2;
    } else {
        //AI棋
        color = 2;
        opponent_color = 1;
    }
    int four_count = 0;
    int pi = 22, pj = 22;
    // ——
    for (int j = max(0,J-5); j < min(11,J); j++) {
        int i=I;
        if ((i != pi || j != pj + 1) && board1[i][j] != color && board1[i][j + 1] != opponent_color && board1[i][j + 2] != opponent_color && board1[i][j + 3] != opponent_color && board1[i][j + 4] != opponent_color &&board1[i][j + 5] != opponent_color&&board1[i][j + 6] != color&& ( board1[i][j + 1] + board1[i][j + 2] + board1[i][j + 3] + board1[i][j + 4]+board1[i][j + 5]) == 4 * color)
        {
            four_count++;
            //std::cout << "发现横向冲四111" << std::endl;
            pi = i;
            pj = j;
        }
    }

    pi = 22;
    pj = 22;
    // |
    for (int i = max(0,I-5); i < min(11,I); i++) {
        int j=J;
        if ((i != pi + 1 || j != pj) && board1[i][j] != color && board1[i + 1][j] != opponent_color && board1[i + 2][j] != opponent_color &&board1[i + 3][j] != opponent_color && board1[i + 4][j] != opponent_color &&board1[i+5][j ] != opponent_color&&board1[i][j + 6] != color&&( board1[i + 1][j] + board1[i + 2][j] + board1[i + 3][j] + board1[i + 4][j]+board1[i + 5][j]) == 4 * color)
        {
            four_count++;
            //std::cout << "发现纵向冲四/活四222"<< std::endl;
            pj = j;
            pi = i;
        }
    }

    pi = 22;
    pj = 22;
    //"\"
    int k=min(I-5,J-5);
    if(k>=0) k=5;
    else k=k+5;
    for (int i = I-k,j = J-k; i < min(11,I)&&j< min(11,J); j++,i++) {
        if ((i != pi + 1 || j != pj + 1) && board1[i][j] != color && board1[i + 1][j + 1] != opponent_color && board1[i + 2][j + 2] != opponent_color && board1[i + 3][j + 3] != opponent_color && board1[i + 4][j + 4] != opponent_color &&board1[i+5][j + 5] != opponent_color&&board1[i+6][j + 6] != color&&(board1[i + 1][j + 1] + board1[i + 2][j + 2] + board1[i + 3][j + 3] + board1[i + 4][j + 4]+board1[i + 5][j +5]) == 4 * color)
        {
            four_count++;
            //std::cout << "发现\\向冲四/活四333"<< std::endl;
            pi = i;
            pj = j;
        }
    }

    pi = 22;
    pj = 22;
    //"/"
    k=min(I-5,16-J-5);
    if(k>=0) k=5;
    else k=k+5;
    for (int i = I-k,j = J+k; i < min(11,I)&&j>= max(5,J); j--,i++)
    {
        if ((i != pi + 1 || j != pj - 1) && board1[i][j] !=color && board1[i + 1][j - 1] != opponent_color && board1[i + 2][j - 2] != opponent_color && board1[i + 3][j - 3] != opponent_color && board1[i + 4][j - 4] != opponent_color &&board1[i+5][j - 5] != opponent_color&&board1[i+6][j - 6] != color&&( board1[i + 1][j - 1] + board1[i + 2][j - 2] + board1[i + 3][j - 3] + board1[i + 4][j - 4]+board1[i + 5][j - 5]) == 4 * color)
        {
            four_count++;
            //std::cout << "发现/向冲四/活四444"<< std::endl;
            pi = i;
            pj = j;
        }
    }

    return four_count;
}

//判断是否存在长连：返回值大于0则存在长连(crtP传参时已经+1）
int Judge_banner::JudgeLongLink(int crtP, int board[N][N],int I,int J)
{
    //横向
    for (int j = max(0,J-5); j < min(10,J); j++) {
        int i=I;
        if (board[i][j] == crtP && board[i][j + 1] == crtP && board[i][j + 2] == crtP && board[i][j + 3] == crtP && board[i][j + 4] == crtP && board[i][j + 5] == crtP) {
            return 1;
        }
    }

    //纵向
    for (int i = max(0,I-5); i < min(10,I); i++) {
        int j=J;
        if (board[i][j] == crtP && board[i + 1][j] == crtP && board[i + 2][j] == crtP && board[i + 3][j] == crtP && board[i + 4][j] == crtP && board[i + 5][j] == crtP) {
            return 1;
        }
    }

    //“\”向
    int k=min(I-5,J-5);
    if(k>=0) k=5;
    else k=k+5;
    for (int i = I-k,j = J-k; i < min(10,I)&&j<min(10,J); j++,i++) {
        if (board[i][j] == crtP && board[i + 1][j + 1] == crtP && board[i + 2][j + 2] == crtP && board[i + 3][j + 3] == crtP && board[i + 4][j + 4] == crtP && board[i + 5][j + 5] == crtP) {
            return 1;
        }
    }

    //“/”向
    k=min(I-5,14-J-5);
    if(k>=0) k=5;
    else k=k+5;
    for (int i = I-k,j = J+k; i < min(10,I)&&j> max(4,J); j--,i++)
    {
        if (board[i][j] == crtP && board[i + 1][j - 1] == crtP && board[i + 2][j - 2] == crtP && board[i + 3][j - 3] == crtP && board[i + 4][j - 4] == crtP && board[i + 5][j - 5] == crtP) {
            return 1;
        }
    }
    return 0;
}
//
int Judge_banner::JudgeFiveLink(int crtP, int board[N][N],int I,int J) {
    //判断是否存在五连：返回值大于0则存在五连

    //横向
    int linknumber=0;
    for(int i=I,j=J;i>=0&&j>=0&&i<N&&j<N;i++){
        if(board[i][j]==crtP+1){
            linknumber++;
        }
        if(board[i][j]!=crtP+1){
            break;
        }
    }
    for(int i=I-1,j=J;i>=0&&j>=0&&i<N&&j<N;i--){
        if(board[i][j]==crtP+1){
            linknumber++;
        }
        if(board[i][j]!=crtP+1){
            break;
        }
    }
    if(linknumber==5){
        return 1;
    }


    //竖向
    linknumber=0;
    for(int i=I,j=J;i>=0&&j>=0&&i<N&&j<N;j++){
        if(board[i][j]==crtP+1){
            linknumber++;
        }
        if(board[i][j]!=crtP+1){
            break;
        }
    }
    for(int i=I,j=J-1;i>=0&&j>=0&&i<N&&j<N;j--){
        if(board[i][j]==crtP+1){
            linknumber++;
        }
        if(board[i][j]!=crtP+1){
            break;
        }
    }
    if(linknumber==5){
        return 1;
    }

    //"\"方向
    linknumber=0;
    for(int i=I,j=J;i>=0&&j>=0&&i<N&&j<N;i++,j++){
        if(board[i][j]==crtP+1){
            linknumber++;
        }
        if(board[i][j]!=crtP+1){
            break;
        }
    }
    for(int i=I-1,j=J-1;i>=0&&j>=0&&i<N&&j<N;i--,j--){
        if(board[i][j]==crtP+1){
            linknumber++;
        }
        if(board[i][j]!=crtP+1){
            break;
        }
    }
    if(linknumber==5){
        return 1;
    }

    //"/"方向
    linknumber=0;
    for(int i=I,j=J;i>=0&&j>=0&&i<N&&j<N;i++,j--){
        if(board[i][j]==crtP+1){
            linknumber++;
        }
        if(board[i][j]!=crtP+1){
            break;
        }
    }
    for(int i=I-1,j=J+1;i>=0&&j>=0&&i<N&&j<N;i--,j++){
        if(board[i][j]==crtP+1){
            linknumber++;
        }
        if(board[i][j]!=crtP+1){
            break;
        }
    }
    if(linknumber==5){
        return 1;
    }


    return 0;
}


int Judge_banner::SecondFour_Live(int crtP, int board[N][N],point point0){

    int I=point0.i;int J=point0.j;
    //cout<<"!!!live"<<I<<" "<<J<<endl;
    int disallow_four=0;
    //横向
    if(point0.drc==0){
        //非边界
        if(J>0&&J+5<N){
            if(board[I][J-1]==0){
                board[I][J]=crtP+1;
                if(CountFour(crtP,board,I,J)>1){
                    board[I][J]=0;
                    disallow_four++;
                }else{
                    board[I][J]=0;
                }
            }else{
                disallow_four++;
            }
            if(board[I][J+5]==0){
                board[I][J+4]=crtP+1;
                if(CountFour(crtP,board,I,J+4)>1){
                    board[I][J+4]=0;
                    disallow_four++;
                }else{
                    board[I][J+4]=0;
                }
            }else{
                disallow_four++;
            }
        }
        //边界
        else if(J==0){
            disallow_four++;
            board[I][J+4]=crtP+1;
            if(CountFour(crtP,board,I,J+4)>1){
                board[I][J+4]=0;
                disallow_four++;
            }else{
                board[I][J+4]=0;
            }
        }
        else{
            disallow_four++;
            board[I][J]=crtP+1;
            if(CountFour(crtP,board,I,J)>1){
                board[I][J]=0;
                disallow_four++;
            }else{
                board[I][J]=0;
            }
        }
    }
    else if(point0.drc==1){
        //非边界
        if(I>0&&I+5<N){
            if(board[I-1][J]==0){
                board[I][J]=crtP+1;
                if(CountFour(crtP,board,I,J)>1){
                    board[I][J]=0;
                    disallow_four++;
                }else{
                    board[I][J]=0;
                }
            }else{
                disallow_four++;
            }
            if(board[I+5][J]==0){
                board[I+4][J]=crtP+1;
                if(CountFour(crtP,board,I+4,J)>1){
                    board[I+4][J]=0;
                    disallow_four++;
                }else{
                    board[I+4][J]=0;
                }
            }else{
                disallow_four++;
            }
        }
        //边界
        else if(I==0){
            disallow_four++;
            board[I+4][J]=crtP+1;
            if(CountFour(crtP,board,I+4,J)>1){
                board[I+4][J]=0;
                disallow_four++;
            }else{
                board[I+4][J]=0;
            }
        }
        else{
            disallow_four++;
            board[I][J]=crtP+1;
            if(CountFour(crtP,board,I,J)>1){
                board[I][J]=0;
                disallow_four++;
            }else{
                board[I][J]=0;
            }
        }
    }
    //"\"
    else if(point0.drc==2){
        //非边界
        if(I>0&&I+5<N&&J>0&&J+5<N){
            if(board[I-1][J-1]==0){
                board[I][J]=crtP+1;
                if(CountFour(crtP,board,I,J)>1){
                    board[I][J]=0;
                    disallow_four++;
                }else{
                    board[I][J]=0;
                }
            }else{
                disallow_four++;
            }
            if(board[I+5][J+5]==0){
                board[I+4][J+4]=crtP+1;
                if(CountFour(crtP,board,I+4,J+4)>1){
                    board[I+4][J+4]=0;
                    disallow_four++;
                }else{
                    board[I+4][J+4]=0;
                }
            }else{
                disallow_four++;
            }
        }
        //边界
        else if(I==0||J==0){
            disallow_four++;
            board[I+4][J+4]=crtP+1;
            if(CountFour(crtP,board,I+4,J+4)>1){
                board[I+4][J+4]=0;
                disallow_four++;
            }else{
                board[I+4][J+4]=0;
            }
        }
        else{
            disallow_four++;
            board[I][J]=crtP+1;
            if(CountFour(crtP,board,I,J)>1){
                board[I][J]=0;
                disallow_four++;
            }else{
                board[I][J]=0;
            }
        }
    }
    //“/”
    else{
        //非边界
        if(I>0&&I+5<N&&J+1<N&&J-5>=0){
            if(board[I-1][J+1]==0){
                board[I][J]=crtP+1;
                if(CountFour(crtP,board,I,J)>1){
                    board[I][J]=0;
                    disallow_four++;
                }else{
                    board[I][J]=0;
                }
            }else{
                disallow_four++;
            }
            if(board[I+5][J-5]==0){
                board[I+4][J-4]=crtP+1;
                if(CountFour(crtP,board,I+4,J-4)>1){
                    board[I+4][J-4]=0;
                    disallow_four++;
                }else{
                    board[I+4][J-4]=0;
                }
            }else{
                disallow_four++;
            }
        }
        //边界
        else if(I==0||J+1==N){
            disallow_four++;
            board[I+4][J-4]=crtP+1;
            if(CountFour(crtP,board,I+4,J-4)>1){
                board[I+4][J-4]=0;
                disallow_four++;
            }else{
                board[I+4][J-4]=0;
            }
        }
        else{
            disallow_four++;
            board[I][J]=crtP+1;
            if(CountFour(crtP,board,I,J)>1){
                board[I][J]=0;
                disallow_four++;
            }else{
                board[I][J]=0;
            }
        }
    }
    if(disallow_four>1){
        return 1;
    }
    else return 0;

}

int Judge_banner::SecondFour_Skip(int crtP, int board[N][N],point point0){

    int I=point0.i;int J=point0.j;

    //cout<<"!!!skip"<<I<<" "<<J<<endl;
    int disallow_four=0;

    //横
    if(point0.drc==0){
        if(board[I][J+2]==0){
            board[I][J+2]=crtP+1;
            if(CountFour(crtP,board,I,J+2)>1){
                board[I][J+2]=0;
                disallow_four++;
            }else{
                board[I][J+2]=0;
            }
        }
        if(board[I][J+3]==0){
            board[I][J+3]=crtP+1;
            if(CountFour(crtP,board,I,J+3)>1){
                board[I][J+3]=0;
                disallow_four++;
            }else{
                board[I][J+3]=0;
            }
        }
    }
    //竖
    else if(point0.drc==1){
        if(board[I+2][J]==0){
            board[I+2][J]=crtP+1;
            if(CountFour(crtP,board,I+2,J)>1){
                board[I+2][J]=0;
                disallow_four++;
            }else{
                board[I+2][J]=0;
            }
        }
        if(board[I+3][J]==0){
            board[I+3][J]=crtP+1;
            if(CountFour(crtP,board,I+3,J)>1){
                board[I+3][J]=0;
                disallow_four++;
            }else{
                board[I+3][J]=0;
            }
        }
        //cout<<"bbb  "<<board[6][10]<<endl;
    }
    //"\"
    else if(point0.drc==2){
        if(board[I+2][J+2]==0){
            board[I+2][J+2]=crtP+1;
            if(CountFour(crtP,board,I+2,J+2)>1){
                board[I+2][J+2]=0;
                disallow_four++;
            }else{
                board[I+2][J+2]=0;
            }
        }
        if(board[I+3][J+3]==0){
            board[I+3][J+3]=crtP+1;
            if(CountFour(crtP,board,I+3,J+3)>1){
                board[I+3][J+3]=0;
                disallow_four++;
            }else{
                board[I+3][J+3]=0;
            }
        }
    }
    //"/"
    else{
        if(board[I+2][J-2]==0){
            board[I+2][J-2]=crtP+1;
            if(CountFour(crtP,board,I+2,J-2)>1){
                board[I+2][J-2]=0;
                disallow_four++;
            }else{
                board[I+2][J-2]=0;
            }
        }
        if(board[I+3][J-3]==0){
            board[I+3][J-3]=crtP+1;
            if(CountFour(crtP,board,I+3,J-3)>1){
                board[I+3][J-3]=0;
                disallow_four++;
            }else{
                board[I+3][J-3]=0;
            }
        }
    }

    return disallow_four;

}

int Judge_banner::SecondFour_Long(int crtP, int board[N][N],point point0){
    int I=point0.i;int J=point0.j;

    //cout<<"!!!long"<<I<<" "<<J<<endl;
    int disallow_four=0;
    if(point0.drc==0){
        if(board[I][J+2]==0){
            board[I][J+2]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J+2)){
                board[I][J+2]=0;
                disallow_four++;
            }else{
                board[I][J+2]=0;
            }
        }
        if(board[I][J+3]==0){
            board[I][J+3]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J+3)){
                board[I][J+3]=0;
                disallow_four++;
            }else{
                board[I][J+3]=0;
            }
        }
        if(board[I][J]==0){
            board[I][J]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J)){
                board[I][J]=0;
                disallow_four++;
            }else{
                board[I][J]=0;
            }
        }
        if(board[I][J+5]==0){
            board[I][J+5]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J+5)){
                board[I][J+5]=0;
                disallow_four++;
            }else{
                board[I][J+5]=0;
            }
        }
    }
    else if(point0.drc==1){

        if(board[I+2][J]==0){
            board[I+2][J]=crtP+1;
            if(JudgeLongLink(crtP+1,board+2,I,J)){
                board[I+2][J]=0;
                disallow_four++;
            }else{
                board[I+2][J]=0;
            }
        }
        if(board[I+3][J]==0){
            board[I+3][J]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I+3,J)){
                board[I+3][J]=0;
                disallow_four++;
            }else{
                board[I+3][J]=0;
            }
        }
        if(board[I][J]==0){
            board[I][J]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J)){
                board[I][J]=0;
                disallow_four++;
            }else{
                board[I][J]=0;
            }
        }
        if(board[I+5][J]==0){
            board[I+5][J]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I+5,J)){
                board[I+5][J]=0;
                disallow_four++;
            }else{
                board[I+5][J]=0;
            }
        }
    }
    else if(point0.drc==2){
        if(board[I+2][J+2]==0){
            board[I+2][J+2]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I+2,J+2)){
                board[I+2][J+2]=0;
                disallow_four++;
            }else{
                board[I+2][J+2]=0;
            }
        }
        if(board[I+3][J+3]==0){
            board[I+3][J+3]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J+3)){
                board[I+3][J+3]=0;
                disallow_four++;
            }else{
                board[I+3][J+3]=0;
            }
        }
        if(board[I][J]==0){
            board[I][J]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J)){
                board[I][J]=0;
                disallow_four++;
            }else{
                board[I][J]=0;
            }
        }
        if(board[I+5][J+5]==0){
            board[I+5][J+5]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J+5)){
                board[I+5][J+5]=0;
                disallow_four++;
            }else{
                board[I+5][J+5]=0;
            }
        }
    }
    else if(point0.drc==3){
        if(board[I+2][J-2]==0){
            board[I+2][J-2]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I+2,J-2)){
                board[I+2][J-2]=0;
                disallow_four++;
            }else{
                board[I+2][J-2]=0;
            }
        }
        if(board[I+3][J-3]==0){
            board[I+3][J-3]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I+3,J-3)){
                board[I+3][J-3]=0;
                disallow_four++;
            }else{
                board[I+3][J-3]=0;
            }
        }
        if(board[I][J]==0){
            board[I][J]=crtP+1;
            if(JudgeLongLink(crtP+1,board,I,J)){
                board[I][J]=0;
                disallow_four++;
            }else{
                board[I][J]=0;
            }
        }
        if(board[I+5][J-5]==0){
            board[I+5][J-5]=crtP+1;
            if(JudgeLongLink(crtP+1 ,board,I+5,J-5)){
                board[I+5][J-5]=0;
                disallow_four++;
            }else{
                board[I+5][J-5]=0;
            }
        }
    }
    return disallow_four;

}
